<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 零度  <2109877665@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2019年08月20日
// +----------------------------------------------------------------------

/**
 * 登陆二维码列表
**/
$title='登陆二维码列表';
include './Head.php';
$my=isset($_GET['my'])?$_GET['my']:$_POST['my'];

if($my=='del'){//删除所有测试商品
	$trade_no=daddslashes($_POST['trade_no']);
	$srow=$DB->query("SELECT * FROM pay_login_qr WHERE trade_no='{$trade_no}' limit 1")->fetch();
	$sql="DELETE FROM `pay_login_qr` WHERE `name`='测试商品' and `pid`='{$conf['zero_pid']}'";
	if($DB->exec($sql)){
		exit("<script language='javascript'>alert('删除所有测试商品成功');history.go(-1);</script>");
	}
}elseif($my=='search') {
	$sql=" `{$_GET['column']}`='{$_GET['value']}'";
	$numrows=$DB->query("SELECT * from pay_login_qr WHERE{$sql}")->rowCount();
	$con='包含 '.$_GET['value'].' 的共有 <b>'.$numrows.'</b> 条记录';
	$link='&my=search&column='.$_GET['column'].'&value='.$_GET['value'];
}else{
	$numrows=$DB->query("SELECT * from pay_login_qr WHERE 1")->rowCount();
	$sql=" 1";
	$con='共有 <b>'.$numrows.'</b> 条记录';
}


echo '
<div class="block">
        <div class="panel-heading"><h3 class="panel-title">操作中心</h3></div>
		<div class="panel-body"><form action="" method="GET" class="form-inline"><input type="hidden" name="my" value="search">
  <div class="form-group">
    <label>条件搜索</label>
	<select name="column" class="form-control"><option value="out_trade_no">商户订单号</option></select>
  </div>
  <div class="form-group">
    <input type="text" class="form-control" name="value" placeholder="搜索内容">
  </div>
  <button type="submit" class="btn btn-primary">搜索</button>
</form>';
?>
	<?php echo '<br>'.$con;?>
      </div>
      </div>
<div class="block">
          <tbody>
		  <form name="form1" id="form1">
	  <div class="table-responsive">
        <table class="table table-striped table-bordered table-vcenter">
          <thead><tr><th>提交过来的URL</th><th>登录二维码</th><th>COOKIE</th><th>类型</th><th>软件产码状态</th><th>登陆码状态</th><th>创建时间/运行时间</th><!--th>操作</th--></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM pay_login_qr WHERE{$sql} order by addtime desc limit $offset,$pagesize");
while($res = $rs->fetch())
{
	echo '<tr><td>'.$res['get_url'].'</td>
	<td>'.($res['up_zt']?'账号密码登陆':($res['qr_url']?($res['type']=='wxpay'?'微信昵称：'.$res['wx_name']:'<img src="'.$res['qr_url'].'" width="50" height="50" />'):'<font color=red>等待软件产码中...</font>')).'</td>
	<td>'.status_cookie($res['type'],$res['cookie'],$res['wx_name'],$res['data_data']).'</td>
    <td>'.pay_type($res['type']).'</td>
	<td>'.status_cookie_zt($res['create_status']).'</td>
	<td>'.($res['msg']).'</td>
	<td>'.$res['addtime'].'<br>'.date("Y-m-d H:i:s",$res['create_status']).'</td>';?>
	<?php echo '</tr>';
}
function status_cookie($type,$cookie,$wx_name,$data_data)//支付方式中文化
{
	if(strstr($type, 'wxpay')){
		if($cookie=='Login_Yes')
			return '['.$wx_name.'] <font color=green>已登录</font>';
		elseif($cookie=='Login_Out')
			return '['.$wx_name.'] <font color=red>已退出</font>';
		else
			return '<font color=red>未登陆</font>';
	}else{
		if($cookie)
			return '<font color=green>成功登陆->'.$data_data.'</font>';
		else
			return '<font color=red>未登陆</font>';
	}
}
function pay_type($type)//支付方式中文化
{
	if(strstr($type, 'qqpay'))
		return '<font color=green>QQ钱包</font>';
	elseif(strstr($type, 'wxpay'))
		return '<font color=green>微信</font>';
	elseif(strstr($type, 'alipay'))
		return '<font color=green>支付宝</font>';
}
function status_cookie_zt($status)//状态
{
	if($status)
		return '<font color=green>协议已执行完成</font>';
	else
		return '<font color=red>协议未执行</font>';
}
function status_status_zt($status)//状态
{
	if($status==1)
		return '<font color=red>已被分配</font>';
	elseif($status==2)
		return '<font color=red>已被锁定</font>';
	elseif($status==3)
		return '<font color=red>分配超时</font>';
	elseif($status==4)
		return '<font color=red>此登陆码无效</font>';
	elseif($status==5)
		return '<font color=red>过期已被删除</font>';
	else
		return '<font color=green>未被分配</font>';
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
?>
    </div>
  </div>
  <script type="text/javascript">
  function Instant_Notify(trade_no){//补单并给回调
		if(trade_no==''){layer.alert('请确保各项不能为空！');return false;}
		  	var ii = layer.load(3, {shade:[0.1,'#fff']});
		  	$.ajax({
				type : "POST",
				url : "?my=Instant_Notify",
				data : {trade_no:trade_no},
				dataType : 'json',
				timeout:15000,
				success : function(data) {					  
					  layer.close(ii);
					  layer.msg(data.msg);
					  if(data.code==1){
						setTimeout(function () {
							location.href="./Order.php";
						}, 1000); //延时1秒跳转
					  }
				},
				error:function(data){
					layer.close(ii);
					layer.msg('服务器错误');
					}
			});
		  	
}
  </script>